package com.runen.wnhz.runen.ui.adapter.puadapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.runen.wnhz.runen.R;

import com.runen.wnhz.runen.bean.SearchResultBean;
import com.runen.wnhz.runen.widget.coustomview.RoundAngleImageView;

import java.util.List;

public class SearchResultAdapter extends BaseAdapter {

    private List<SearchResultBean.DataBean.ListBean> listBeans;

    private Context context;

    public SearchResultAdapter(List<SearchResultBean.DataBean.ListBean> listBeans, Context context) {
        this.listBeans = listBeans;
        this.context = context;
    }

    @Override
    public int getCount() {
        if(listBeans == null){
            return 0;
        }else {
            return listBeans.size();
        }
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if(convertView == null){
            convertView = View.inflate(context,R.layout.search_result_liat_item_layout,null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder)convertView.getTag();
        }

        SearchResultBean.DataBean.ListBean listBean = listBeans.get(position);
        Glide.with(context).load(listBean.getPic()).into(viewHolder.image_searchLessonLog);
        viewHolder.lesson_learnNum.setText(listBean.getViews() + "人学习");
        viewHolder.lesson_name.setText(listBean.getTitle());
        viewHolder.lesson_price.setText("￥" + listBean.getPrice());
        viewHolder.rb_star.setRating(Float.parseFloat(listBean.getStar()));
        return convertView;
    }

    private static class ViewHolder{
        RoundAngleImageView image_searchLessonLog;
        TextView lesson_name;
        RatingBar rb_star;
        TextView lesson_learnNum;
        TextView lesson_price;

        public ViewHolder(View convertView) {
            this.image_searchLessonLog = convertView.findViewById(R.id.image_searchLessonLog);
            this.lesson_name = convertView.findViewById(R.id.lesson_name);
            this.rb_star = convertView.findViewById(R.id.rb_star);
            this.lesson_learnNum = convertView.findViewById(R.id.lesson_learnNum);
            this.lesson_price = convertView.findViewById(R.id.lesson_price);
        }
    }
}
